package com.bishitest;

import com.bishitest.domain.OrderList;
import com.bishitest.domain.OrderListRecord;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author XuFan
 * @create 2025-08-19-17:16
 */
public class Test {

    public static BigDecimal appleUnitPrice = BigDecimal.valueOf(8.0);
    public static BigDecimal strawberryUnitPrice = BigDecimal.valueOf(13.0);
    public static BigDecimal strawberryDiscountUnitPrice = BigDecimal.valueOf(10.4);
    public static BigDecimal mangoUnitPrice = BigDecimal.valueOf(20.0);

    public static void main(String[] args) {

        //顾客A购买了10斤水果
        System.out.println("顾客A购买了：");
        getTotalPrice(10, false, false, false);

        //顾客B购买了10斤水果
        System.out.println("顾客B购买了：");
        getTotalPrice(10, true, false, false);

        //顾客C购买了10斤水果
        System.out.println("顾客C购买了：");
        getTotalPrice(10, true, true, false);

        //顾客D购买了10斤水果
        System.out.println("顾客D购买了：");
        getTotalPrice(10, true, true, true);
    }


    public static void getTotalPrice(int fruitCattyNum, boolean hasMango, boolean strawberryHasDiscount, boolean totalPriceHasReduce) {
        int AppleNum;
        int strawberryNum;
        int mangoNum;

        for (AppleNum = 0; AppleNum <= fruitCattyNum; AppleNum++) {
            if (hasMango) {//只买了苹果，草莓，芒果
                int strawberryAndMangoNum = fruitCattyNum - AppleNum;
                for (strawberryNum = 0; strawberryNum <= strawberryAndMangoNum; strawberryNum++) {
                    mangoNum = strawberryAndMangoNum - strawberryNum;
                    if (AppleNum == 0 || strawberryNum == 0 || mangoNum == 0) continue;
                    OrderList orderList = creatOrder(AppleNum, strawberryNum, mangoNum, hasMango, strawberryHasDiscount, totalPriceHasReduce);
                    System.out.println(AppleNum + "斤苹果，" + strawberryNum + "斤草莓，" + mangoNum + "斤芒果。总价为" + orderList.orderListTotalPrice +"元。");
                }
            } else {//只买了苹果和草莓
                strawberryNum = fruitCattyNum - AppleNum;
                if (AppleNum == 0 || strawberryNum == 0) continue;
                OrderList orderList = creatOrder(AppleNum, strawberryNum, 0, hasMango, strawberryHasDiscount, totalPriceHasReduce);
                System.out.println(AppleNum + "斤苹果，" + strawberryNum + "斤草莓。总价为" + orderList.orderListTotalPrice +"元。");
            }
        }
    }

    public static OrderList creatOrder(int AppleNum, int strawberryNum, int mangoNum, boolean hasMango, boolean strawberryHasDiscount, boolean totalPriceHasReduce) {
        List<OrderListRecord> records = new ArrayList<>();
        records.add(new OrderListRecord("苹果", AppleNum, appleUnitPrice));
        records.add(new OrderListRecord("草莓", strawberryNum, strawberryHasDiscount ? strawberryDiscountUnitPrice : strawberryUnitPrice));
        if (hasMango) records.add(new OrderListRecord("芒果", mangoNum, mangoUnitPrice));
        return new OrderList(records, totalPriceHasReduce);
    }

}
